<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Books extends Model
{
    const MODULE = [
        ['id' => 1, 'name' => '小说'],
        ['id' => 2, 'name' => '漫画']
    ];
    const MODULE_ID = [1 => '小说', 2 => '漫画'];
    protected $table = 'book';
    protected $fillable = [
        'name', 'cover', 'intro', 'author', 'type_id', 'user_id'
    ];


    public function user()
    {
        return $this->belongsTo(User::class);
    }

    //书籍章节
    public function bookchapters()
    {
        return $this->hasMany(BookChapters::class, 'book_id', 'id');
    }

    //书籍评论
    public function bookcomments()
    {
        return $this->hasMany(BookComments::class);
    }

    //评分
    public function bookscore()
    {
        return $this->hasMany(BookScore::class, 'book_id', 'id');
    }
}
